<template>
  <el-container class="box">
    <el-aside :width="btnIcon ? '64px' : '300px'">
      <div class="logo-box">
        <img src="@/assets/img/shop.png" alt="" />
        <span v-if="!btnIcon">网博商城管理系统</span>
      </div>

      <el-menu
        background-color="#545c64"
        text-color="#fff"
        active-text-color="#ffd04b"
        :default-active="$route.path"
        :router="true"
        :unique-opened="true"
      >
        <el-submenu v-for="item in menus" :key="item.id" :index="item.id+''">
          <template #title>
            <i :class="iconList[item.id]"></i>
            <span>{{item.authName}}</span>
          </template>
          <el-menu-item v-for="pm in item.children" :key="pm.id" :index="'/home/'+pm.path">
            <i class="el-icon-menu"></i>
            <span>{{pm.authName}}</span>
          </el-menu-item>
        </el-submenu>
      </el-menu>
    </el-aside>
    <el-container>
      <el-header>
        <el-button>
          <i
            :class="btnIcon ? 'el-icon-s-unfold' : 'el-icon-s-fold'"
            @click="btnIcon = !btnIcon"
          ></i>
        </el-button>
        <UserLogout></UserLogout>
      </el-header>
      <el-main>
        
        <router-view></router-view>

      </el-main>
    </el-container>
  </el-container>
</template>
<script>
import UserLogout from "@/views/home/UserLogout";
export default {
  data() {
    return {
      btnIcon: false,
      user: {},
      menus:[],
      iconList:{
        "201":"el-icon-s-home",
        "125":"el-icon-user-solid",
        "103":"el-icon-s-opportunity",
        "101":"el-icon-s-cooperation",
        "102":"el-icon-s-order",
      }
    };
  },
  components: {
    UserLogout,
  },
  methods: {
    async initLeftMenu(){
      try {
        let menus = await this.$api.getLeftMenu()
        this.menus = menus
      } catch (error) {
        console.log("HomeView-initLeftMenu-error:",error)
      }
    }
  },
  created() {
    this.initLeftMenu()
  },
};
</script>
<style lang="less" scoped>
.box {
  height: 100%;
  background-color: #efefef;
  .el-aside {
    background-color: #545c64;
    color: white;
    .logo-box {
      width: 100%;
      height: 60px;
      box-sizing: border-box;
      border-bottom: 1px solid white;
      display: flex;
      flex-direction: row;
      line-height: 60px;
      font-size: 25px;
      img {
        width: 50px;
        height: 50px;
        margin: 5px;
      }
    }
  }
  .el-header {
    background-color: white;
    box-shadow: 0px 0px 12px #999;
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 10;
    .el-dropdown {
      display: flex;
      align-items: center;
      cursor: pointer;
      img {
        width: 40px;
      }
    }
  }
}
</style>